<?php
/**
 * Created by PhpStorm.
 * User: yf
 * Date: 2018/3/3
 * Time: 下午6:14
 */

namespace App\HttpController;


use EasySwoole\Core\Http\AbstractInterface\Controller;
use EasySwoole\Core\Http\Message\Status;
use EasySwoole\Core\Swoole\ServerManager;

class Index extends Controller
{
    /* document
     *  getActionName()        获得当前被请求的方法名称
     *  writeJson($statusCode = 200,$result = null,$msg = null)     直接输出 Json 数据到浏览器
     *  validateParams(Rules $rules)    校验当前请求参数
     * */



    // 默认的控制器
    // 当前留着有什么作用





    //测试路径 /index.html
    public function index()
    {
        // TODO: Implement index() method.
        $this->response()->write('hello world');
    }

    //测试路径 /test/index.html
    public function test()
    {
        $ip = ServerManager::getInstance()->getServer()->connection_info($this->request()->getSwooleRequest()->fd);
        var_dump($ip);
        $ip2 = $this->request()->getHeaders();
        var_dump($ip2);
        $this->response()->write('index controller test');
    }



    protected function actionNotFound($action): void
    {
        $this->response()->withStatus(Status::CODE_NOT_FOUND);
        $this->response()->write("{$action} is not exist");
    }

    public function a()
    {
        $this->response()->write('index controller router');
    }

    public function a2()
    {
        $this->response()->write('index controller router2');
    }

    public function test2(){
        $this->response()->write('this is controller test2 and your id is '.$this->request()->getRequestParam('id'));
    }

}